//
//  PopPresentationController.swift
//  Weibo007
//
//  Created by 闫崇 on 15/12/17.
//  Copyright © 2015年 闫崇. All rights reserved.
//

import UIKit

class PopPresentationController: UIPresentationController {

    
    var presentFrame = CGRectZero
    
    //遮罩视图
    lazy var dummyView : UIView = {
       
        let v = UIView()
        v.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        
        //为遮罩视图添加手势
        let tap = UITapGestureRecognizer(target: self, action: "close")
        
        v.addGestureRecognizer(tap)
        
        return v
    }()
    
    
    
    //手势的执行方法
    func close() {
        
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
        
    }
    

    //容器视图将要重新布局子视图
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        //添加并且设置 dummyView
        dummyView.frame = containerView!.bounds
        containerView?.insertSubview(dummyView, atIndex: 0)
        
        
        //设置视图的大小
        presentedView()?.frame = presentFrame
    }
    
    
    
}
